#include "LeagueHistory.h"
#include "ServiceProvider.h"
#include "MatchData.h"
#include "ZStream.h"

void LeagueItemHistory::Serialize(ZStream& o_stream) const
{
	o_stream.WriteOpenTag("LeagueItemHistory");
	
	o_stream.WriteAttribute("SeasonNum", m_year);
	o_stream.WriteAttribute("HistoryNum", m_result.size());

	for (size_t i = 0; i < m_result.size(); ++i)
		m_result[i].Serialize(o_stream);
	
	o_stream.WriteCloseTag("LeagueItemHistory");
}

void LeagueItemHistory::Deserialize(ZStream& i_stream)	
{
	i_stream.SkipLine();
	
	i_stream.ReadAttribute(m_year);

	size_t historyNum;

	i_stream.ReadAttribute(historyNum);

	m_result.clear();
	m_result.reserve(historyNum);

	for (size_t i = 0; i < historyNum; ++i)
	{
		TeamScore history;
		history.Deserialize(i_stream);
		m_result.push_back(history);
	}
	
	i_stream.SkipLine();
}

//LeagueHistory
LeagueHistory::LeagueHistory()
{
}

ZStream& LeagueHistory::Serialize(ZStream& o_stream) const
{
	o_stream.WriteOpenTag("LeagueHistory");

	o_stream.WriteAttribute("HistoryNum", m_items.size());

	for (LeagueItemHistoryVecCit it = m_items.begin(); it != m_items.end(); ++it)
		it->Serialize(o_stream);

	o_stream.WriteCloseTag("LeagueHistory");

	return o_stream;
}

ZStream& LeagueHistory::Deserialize(ZStream& i_stream)
{
	i_stream.SkipLine();

	size_t historyNum;

	i_stream.ReadAttribute(historyNum);

	m_items.clear();
	m_items.reserve(historyNum);

	for (size_t i = 0; i < historyNum; ++i)
	{
		LeagueItemHistory history;
		history.Deserialize(i_stream);
		m_items.push_back(history);
	}

	i_stream.SkipLine();

	return i_stream;
}

